package cn.mpq.payment.config;

import cn.mpq.payment.common.Interceptor.LoginInterceptor;
import cn.mpq.payment.common.Interceptor.UserLoginArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * web MVC 适配器 * 配置拦截器、处理静态资源、配置消息转换等
 * Created by camelot on 2017/10/17.
 */
@Component
public class EcmWebMvcConfig extends WebMvcConfigurerAdapter {
    @Autowired
    private LoginInterceptor loginInterceptor;
    /**
     * 注册拦截器
     * @param registry 拦截器注册中心
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**");
    }

    /**
     * 添加参数解析，将参数的形式从下划线转化为驼峰
     * @param argumentResolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        super.addArgumentResolvers(argumentResolvers);
        argumentResolvers.add(new UserLoginArgumentResolver());
    }

}

